import React, { useReducer } from 'react'

const reducer = (oldstate, action)=>{
    let newlist = {...oldstate};
    switch(action.type){
        case 'mul':
            newlist.count--;
            return newlist;
        case 'add':
            newlist.count++;
            return newlist;
        default:
            return oldstate;
    }
}

const initvalue = {
    count:0
}

export default function App() {
  const [state, dispatch] = useReducer(reducer, initvalue)
  return (
    <div>
        <button onClick={()=>{
            dispatch({
                type:'mul'
            })
        }}>-</button>
        {state.count}
        <button onClick={()=>{
            dispatch({
                type:'add'
            })
        }}>+</button>
    </div>
  )
}
